/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlaceOrder.java
 *
 * Created on Jul 2, 2009, 11:02:53 AM
 */
import com.omnesys.nestq.classes.OrderParams;
import com.omnesys.nestq.classes.SymbolData;

import java.util.Vector;


/**
 *
 * @author Pankaj
 */
public class PlaceOrder extends javax.swing.JFrame implements Runnable {
  /** Creates new form PlaceOrder */
  private SymbolData ExchSeg;
  private boolean flag1;

  public PlaceOrder() {
    init();
  }

  public void init() {
    flag1 = HomePage.nc.bUserEnable;
    HomePage.listSymbols = new Vector();
    HomePage.listSymbols.add("Scrip names");
    HomePage.listExchanges = new Vector();
    java.awt.EventQueue.invokeLater(this);
    initComponents();
    HomePage.nc.GetAllExchanges(this, "JAPI");

    //        if(HomePage.listExchanges != null && HomePage.listExchanges.size() > 0)
    //           HomePage.nc.GetAllSymbols(this,(String)HomePage.listExchanges.get(0));
  }

  public void initExchanges() {
    System.out.println("init exchanges called");

    if ((HomePage.listExchanges != null) &&
          (HomePage.listExchanges.get(0) != null) &&
          (HomePage.listExchanges.get(0).toString().length() > 0)) {
      ExchJComboBox1.removeAllItems();

      int nExch = HomePage.listExchanges.size();
      System.out.println("--------------:-----------------" + nExch);

      for (int i = 0; i < nExch; i++) {
        ExchJComboBox1.addItem(HomePage.listExchanges.get(i));
      }

      System.out.println(" calling GETSYMBOLS FROM  PLACEORDERAPI  ");
      // ExchSeg.sExchSeg=ExchJComboBox1.getSelectedItem().toString();
      //  System.out.println("  ExchSeg.sExchSeg"+ExchSeg.sExchSeg);
      HomePage.nc.GetAllSymbols(this, HomePage.listExchanges.get(0).toString(),
                                "JAPI");

      ExchJComboBox1.repaint();
    }
  }

  public void initSymbols() {
    System.out.println("init symbols called");
    ScripNameJComboBox4.removeAllItems();

    int nScrips = HomePage.listSymbols.size();

    for (int i = 0; i < nScrips; i++) {
      ScripNameJComboBox4.addItem(HomePage.listSymbols.get(i));
    }

    //        ScripNameJComboBox4.setModel(new javax.swing.DefaultComboBoxModel(HomePage.listSymbols));
    //        ScripNameJComboBox4 = new JComboBox(HomePage.listSymbols);
    ScripNameJComboBox4.repaint();
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

    jLabel1 = new javax.swing.JLabel();
    ExchJComboBox1 = new javax.swing.JComboBox();
    BSJComboBox2 = new javax.swing.JComboBox();
    OrdTypeJComboBox3 = new javax.swing.JComboBox();
    ScripNameJComboBox4 = new javax.swing.JComboBox();
    QtyJTextField1 = new javax.swing.JTextField();
    OrderPriceJTextField2 = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();
    jLabel2 = new javax.swing.JLabel();
    AccIDJTextField4 = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    TrigPriceJTextField3 = new javax.swing.JTextField();
    ProductJComboBox5 = new javax.swing.JComboBox();
    CustomerFirmJComboBox6 = new javax.swing.JComboBox();
    jLabel4 = new javax.swing.JLabel();
    DisQtyJTextField1 = new javax.swing.JTextField();
    ValidityJComboBox = new javax.swing.JComboBox();
    jLabelNestOrderNumber = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    ValdityDate = new javax.swing.JTextField();
    jLabel6 = new javax.swing.JLabel();
    UserId = new javax.swing.JTextField();

    setResizable(false);

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 13));
    jLabel1.setText("Place Order");

    ExchJComboBox1.setModel(new javax.swing.DefaultComboBoxModel(HomePage.listExchanges));

    org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
                                                                                                     ExchJComboBox1,
                                                                                                     org.jdesktop.beansbinding.ObjectProperty.create(),
                                                                                                     ExchJComboBox1,
                                                                                                     org.jdesktop.beansbinding.BeanProperty.create("elements"),
                                                                                                     "Exchange");
    bindingGroup.addBinding(binding);

    ExchJComboBox1.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
          ExchJComboBox1ItemStateChanged(evt);
        }
      });

    BSJComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
                                                                 "Buy", "Sell"
                                                               }));

    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
                                                                   BSJComboBox2,
                                                                   org.jdesktop.beansbinding.ObjectProperty.create(),
                                                                   BSJComboBox2,
                                                                   org.jdesktop.beansbinding.BeanProperty.create("elements"),
                                                                   "BuySell");
    bindingGroup.addBinding(binding);

    OrdTypeJComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
                                                                      "Market Order",
                                                                      "Limit Order",
                                                                      "SL",
                                                                      "SL-M"
                                                                    }));

    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
                                                                   OrdTypeJComboBox3,
                                                                   org.jdesktop.beansbinding.ObjectProperty.create(),
                                                                   OrdTypeJComboBox3,
                                                                   org.jdesktop.beansbinding.BeanProperty.create("elements"),
                                                                   "OrderType");
    bindingGroup.addBinding(binding);

    OrdTypeJComboBox3.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
          OrdTypeJComboBox3ItemStateChanged(evt);
        }
      });

    ScripNameJComboBox4.setModel(new javax.swing.DefaultComboBoxModel(HomePage.listSymbols));

    QtyJTextField1.setText("0");

    OrderPriceJTextField2.setText("0.0");
    OrderPriceJTextField2.setEnabled(false);

    jButton1.setText("Place Order");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
          jButton1ActionPerformed(evt);
        }
      });

    jButton3.setText("Cancel");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
          jButton3ActionPerformed(evt);
        }
      });

    jLabel2.setText("Exch Seg  Buy/Sell        Order Type           Scrip Name            Product Type     Validity");

    if (!flag1) {
      AccIDJTextField4.setName("na");
      AccIDJTextField4.setEnabled(false);
    }

    jLabel3.setText("Quantity          Disclosed Qty    Order Price   Trigger Price    Account ID");

    TrigPriceJTextField3.setText("0.0");
    TrigPriceJTextField3.setEnabled(false);

    ProductJComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
                                                                      "ARB",
                                                                      "NRML",
                                                                      "CNC",
                                                                      "MIS",
                                                                      "MLB"
                                                                    }));

    CustomerFirmJComboBox6.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
                                                                           "CLI"
                                                                         }));
    CustomerFirmJComboBox6.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
          CustomerFirmJComboBox6ItemStateChanged(evt);
        }
      });

    jLabel4.setForeground(new java.awt.Color(255, 0, 0));

    DisQtyJTextField1.setText("0");

    ValidityJComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
                                                                      "DAY",
                                                                      "IOC",
                                                                      "GTC"
                                                                    }));

    jLabelNestOrderNumber.setText("");

    jLabel5.setText("Date(dd-mm-yy)");

    ValdityDate.setText("");

    jLabel6.setText("UserId");

    UserId.setText("");

    if (!flag1) {
      UserId.setName("na");
      UserId.setEnabled(false);
    }

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                                    .addGroup(layout.createSequentialGroup()
                                                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                                                                                         false)
                                                                                                    .addGroup(layout.createSequentialGroup()
                                                                                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                                    .addGroup(layout.createSequentialGroup()
                                                                                                                                                    .addContainerGap()
                                                                                                                                                    .addComponent(QtyJTextField1,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                                                  69,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                                                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                                                                    .addComponent(DisQtyJTextField1,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                                                  87,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE))
                                                                                                                                    .addGroup(layout.createSequentialGroup()
                                                                                                                                                    .addGap(32,
                                                                                                                                                            32,
                                                                                                                                                            32)
                                                                                                                                                    .addComponent(jButton3,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                                                  107,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                                                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                                    .addComponent(jButton1)
                                                                                                                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                                                                                                              layout.createSequentialGroup()
                                                                                                                                                    .addComponent(OrderPriceJTextField2,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                                                  68,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                                                                                    .addGap(18,
                                                                                                                                                            18,
                                                                                                                                                            18)
                                                                                                                                                    .addComponent(TrigPriceJTextField3,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                                                  73,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                                                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                                    .addComponent(AccIDJTextField4,
                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                  81,
                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                                                    .addGap(18,
                                                                                                                            18,
                                                                                                                            18)
                                                                                                                    .addComponent(UserId))
                                                                                                    .addGroup(layout.createSequentialGroup()
                                                                                                                    .addContainerGap()
                                                                                                                    .addComponent(jLabel2,
                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                  541,
                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE))
                                                                                                    .addGroup(layout.createSequentialGroup()
                                                                                                                    .addContainerGap()
                                                                                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                                                                                                    .addGroup(layout.createSequentialGroup()
                                                                                                                                                    .addComponent(ExchJComboBox1,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                                                  65,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                                                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                                                                    .addComponent(BSJComboBox2,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                                                  javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                                                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                                                                    .addComponent(OrdTypeJComboBox3,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                                                  javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                                                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                                                                    .addComponent(ScripNameJComboBox4,
                                                                                                                                                                  0,
                                                                                                                                                                  201,
                                                                                                                                                                  Short.MAX_VALUE)
                                                                                                                                                    .addGap(29,
                                                                                                                                                            29,
                                                                                                                                                            29)
                                                                                                                                                    .addComponent(ProductJComboBox5,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                                                  82,
                                                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE))
                                                                                                                                    .addGroup(layout.createSequentialGroup()
                                                                                                                                                    .addComponent(jLabel6)
                                                                                                                                                    .addGap(32,
                                                                                                                                                            32,
                                                                                                                                                            32)))
                                                                                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                                    .addComponent(ValidityJComboBox,
                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                  javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                                                    .addGap(31,
                                                                                            31,
                                                                                            31)
                                                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                    .addComponent(jLabel5)
                                                                                                    .addGroup(layout.createSequentialGroup()
                                                                                                                    .addComponent(ValdityDate,
                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                  136,
                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                                                    .addGap(50,
                                                                                                                            50,
                                                                                                                            50)
                                                                                                                    .addComponent(CustomerFirmJComboBox6,
                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                  77,
                                                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE))))
                                                                    .addGroup(layout.createSequentialGroup()
                                                                                    .addGap(175,
                                                                                            175,
                                                                                            175)
                                                                                    .addComponent(jLabel1,
                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                  297,
                                                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                    .addGap(164, 164, 164)
                                                    .addComponent(jLabel4,
                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                  179,
                                                                  javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                                    .addContainerGap()
                                                    .addComponent(jLabel3,
                                                                  javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                  354,
                                                                  Short.MAX_VALUE)
                                                    .addGap(841, 841, 841))
                                    .addGroup(layout.createSequentialGroup()
                                                    .addGap(42, 42, 42)
                                                    .addComponent(jLabelNestOrderNumber,
                                                                  javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                  208,
                                                                  javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addContainerGap(955,
                                                                     Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                  .addGroup(layout.createSequentialGroup()
                                                  .addContainerGap()
                                                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                                  .addGroup(layout.createSequentialGroup()
                                                                                  .addComponent(jLabel4)
                                                                                  .addGap(30,
                                                                                          30,
                                                                                          30))
                                                                  .addGroup(layout.createSequentialGroup()
                                                                                  .addComponent(jLabel1)
                                                                                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                                                                  .addComponent(jLabel2)
                                                                                                  .addComponent(jLabel5))))
                                                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                                  .addComponent(ExchJComboBox1,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(BSJComboBox2,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(OrdTypeJComboBox3,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(ScripNameJComboBox4,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(ProductJComboBox5,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(ValidityJComboBox,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(ValdityDate,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(CustomerFirmJComboBox6,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                  .addGap(11, 11, 11)
                                                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                                  .addComponent(jLabel3)
                                                                  .addComponent(jLabel6))
                                                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                                  .addComponent(QtyJTextField1,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(DisQtyJTextField1,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(TrigPriceJTextField3,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(OrderPriceJTextField2,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(AccIDJTextField4,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                  .addComponent(UserId,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                                  .addComponent(jButton3)
                                                                  .addComponent(jButton1))
                                                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                   35,
                                                                   Short.MAX_VALUE)
                                                  .addComponent(jLabelNestOrderNumber)
                                                  .addGap(25, 25, 25)));

    bindingGroup.bind();

    pack();
  } // </editor-fold>//GEN-END:initComponents

  private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_jButton3ActionPerformed
    this.dispose();

    //        this.setVisible(false);
  } //GEN-LAST:event_jButton3ActionPerformed

  //place order
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_jButton1ActionPerformed

    try {
      boolean flag = false;

      OrderParams orderParams = new OrderParams();

      orderParams.sOrderType = ((String) OrdTypeJComboBox3.getSelectedItem()).trim();

      if (orderParams.sOrderType.equalsIgnoreCase("Market Order")) {
        orderParams.sOrderType = "MKT";
      } else if (orderParams.sOrderType.equalsIgnoreCase("Limit Order")) {
        orderParams.sOrderType = "L";
      }

      if ((QtyJTextField1.getText() == null) ||
            (QtyJTextField1.getText().length() == 0)) {
        QtyJTextField1.setText("0");
      }

      orderParams.lQuantity = Long.parseLong(QtyJTextField1.getText());

      if (orderParams.lQuantity <= 0) {
        flag = true;
      }

      if ((DisQtyJTextField1.getText() == null) ||
            (DisQtyJTextField1.getText().length() == 0)) {
        DisQtyJTextField1.setText("0");
      }

      orderParams.lDiscQuantity = Long.parseLong(DisQtyJTextField1.getText());

      if (orderParams.lDiscQuantity < 0) {
        flag = true;
      }

      if ((OrderPriceJTextField2.getText() == null) ||
            (OrderPriceJTextField2.getText().length() == 0)) {
        OrderPriceJTextField2.setText("0.0");
      }

      orderParams.dPrice = 100 * Double.parseDouble(OrderPriceJTextField2.getText());

      if ((orderParams.sOrderType.equalsIgnoreCase("L") ||
            orderParams.sOrderType.equalsIgnoreCase("SL")) &&
            (orderParams.dPrice <= 0)) {
        flag = true;
      }

      orderParams.sExchSeg = (String) ExchJComboBox1.getSelectedItem();
      orderParams.sTrdSymbol = (String) ScripNameJComboBox4.getSelectedItem();

      if (orderParams.sTrdSymbol.equalsIgnoreCase("Scrip names")) {
        flag = true;
      }

      orderParams.sTransType = (String) BSJComboBox2.getSelectedItem();
      orderParams.sTransType = "" + orderParams.sTransType.charAt(0);

      if ((TrigPriceJTextField3.getText() == null) ||
            (TrigPriceJTextField3.getText().length() == 0)) {
        TrigPriceJTextField3.setText("0.0");
      }

      orderParams.dTriggerPrice = 100 * Double.parseDouble(TrigPriceJTextField3.getText());
      System.out.println("trig price " + orderParams.dTriggerPrice);

      if ((orderParams.sOrderType.equalsIgnoreCase("SL") ||
            orderParams.sOrderType.equalsIgnoreCase("SL-M")) &&
            (orderParams.dTriggerPrice <= 0)) {
        flag = true;
      }

      if (flag1) {
        orderParams.sAccountId = AccIDJTextField4.getText();
        orderParams.sUserId = UserId.getText();

        if ((orderParams.sAccountId == null) ||
              (orderParams.sAccountId.length() == 0)) {
          flag = true;
        }

        if ((orderParams.sUserId == null) ||
              (orderParams.sUserId.length() == 0)) {
          flag = true;
        }
      } else {
        orderParams.sAccountId = "SET";
        orderParams.sUserId = "SET";
      }

      //

      //
      orderParams.sCustomerFirm = ((String) CustomerFirmJComboBox6.getSelectedItem()).trim();
      orderParams.sCustomerFirm = "" + orderParams.sCustomerFirm.charAt(0);

      if ((orderParams.sCustomerFirm == null) ||
            (orderParams.sCustomerFirm.length() == 0)) {
        flag = true;
      }

      orderParams.sProduct = (String) ProductJComboBox5.getSelectedItem();

      if (orderParams.sProduct.equalsIgnoreCase("mlb")) {
        orderParams.sProduct = "ML";
      }

      orderParams.sOrdDuration = (String) ValidityJComboBox.getSelectedItem();
      orderParams.sValidDate = (String) ValdityDate.getText();

      if (flag) {
        jLabel4.setText("All data fields must be filled");
      } else {
        //placing order
        System.out.println("Placing order:");
        HomePage.nc.PlaceOrder(this, orderParams);
      }
    } catch (Exception e) {
      System.out.println("Wrong data when placing order");
      e.printStackTrace();
    }
  } //GEN-LAST:event_jButton1ActionPerformed

  private void ExchJComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) { //GEN-FIRST:event_ExchJComboBox1ItemStateChanged

    String str = evt.getItem().toString();

    System.out.println(str);
    HomePage.nc.GetAllSymbols(this, str, "JAPI");
  } //GEN-LAST:event_ExchJComboBox1ItemStateChanged

  private void OrdTypeJComboBox3ItemStateChanged(java.awt.event.ItemEvent evt) { //GEN-FIRST:event_OrdTypeJComboBox3ItemStateChanged
    System.out.println("order type state channged " +
                       OrdTypeJComboBox3.getSelectedItem());

    String itemSelected = ((String) OrdTypeJComboBox3.getSelectedItem()).trim();

    if (itemSelected.equalsIgnoreCase("Market Order")) {
      OrderPriceJTextField2.disable();
      TrigPriceJTextField3.disable();
    } else if (itemSelected.equalsIgnoreCase("limit order") ||
                 itemSelected.equalsIgnoreCase("au")) {
      OrderPriceJTextField2.enable();
      TrigPriceJTextField3.disable();
    } else if (itemSelected.equalsIgnoreCase("sl")) {
      OrderPriceJTextField2.enable();
      TrigPriceJTextField3.enable();
    } else if (itemSelected.equalsIgnoreCase("sl-m")) {
      OrderPriceJTextField2.disable();
      TrigPriceJTextField3.enable();
    }

    OrderPriceJTextField2.repaint();
    TrigPriceJTextField3.repaint();
  } //GEN-LAST:event_OrdTypeJComboBox3ItemStateChanged

  private void CustomerFirmJComboBox6ItemStateChanged(java.awt.event.ItemEvent evt) { //GEN-FIRST:event_CustomerFirmJComboBox6ItemStateChanged

    String itemStateChanged = ((String) CustomerFirmJComboBox6.getSelectedItem()).trim();

    if (itemStateChanged.equals("PRO")) {
      AccIDJTextField4.disable();
    } else if (itemStateChanged.equals("CLI")) {
      AccIDJTextField4.enable();
    }

    AccIDJTextField4.repaint();
  } //GEN-LAST:event_CustomerFirmJComboBox6ItemStateChanged

  /**
  * @param args the command line arguments
  */

  /*    public static void main(String args[]) {
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  new PlaceOrder().setVisible(true);
              }
          });
      }*/
  public void run() {
    this.setVisible(true);
  }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  javax.swing.JTextField AccIDJTextField4;
  javax.swing.JComboBox BSJComboBox2;
  javax.swing.JComboBox CustomerFirmJComboBox6;
  private javax.swing.JTextField DisQtyJTextField1;
  javax.swing.JComboBox ExchJComboBox1;
  javax.swing.JComboBox OrdTypeJComboBox3;
  javax.swing.JTextField OrderPriceJTextField2;
  javax.swing.JComboBox ProductJComboBox5;
  javax.swing.JTextField QtyJTextField1;
  javax.swing.JComboBox ScripNameJComboBox4;
  javax.swing.JTextField TrigPriceJTextField3;
  private javax.swing.JTextField UserId;
  private javax.swing.JTextField ValdityDate;
  private javax.swing.JComboBox ValidityJComboBox;
  javax.swing.JButton jButton1;
  javax.swing.JButton jButton3;
  javax.swing.JLabel jLabel1;
  javax.swing.JLabel jLabel2;
  javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  public javax.swing.JLabel jLabelNestOrderNumber;
  private org.jdesktop.beansbinding.BindingGroup bindingGroup;

  // End of variables declaration//GEN-END:variables
}
